package com.zjitc.serviceedu.service.impl;

import com.zjitc.serviceedu.entity.EduEssay;
import com.zjitc.serviceedu.entity.vo.EssayAvatarVo;
import com.zjitc.serviceedu.mapper.EduEssayMapper;
import com.zjitc.serviceedu.service.EduEssayService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 赵诚挚
 * @since 2024-10-14
 */
@Service
public class EduEssayServiceImpl extends ServiceImpl<EduEssayMapper, EduEssay> implements EduEssayService {


    @Override
    public List<EssayAvatarVo> getAvatar(EssayAvatarVo essayAvatarVo) {
        List<EssayAvatarVo> essayAvatarVos = baseMapper.selectAvatar(essayAvatarVo);
        return essayAvatarVos;
    }

    @Override
    public EssayAvatarVo getTeacherId(Long teacherId) {
      EssayAvatarVo essayAvatarVo =  baseMapper.selectTeacherId(teacherId);
      return essayAvatarVo;
    }

    @Override
    public boolean updateBrowse(Long id) {
        EduEssay essay = this.getById(id);
        if (essay != null) {
            essay.setBrowse(essay.getBrowse() + 1); // 销量+1
            return this.updateById(essay); // 更新课程信息
        }
        return false;
    }

    @Override
    public boolean updateThumbUp(Long id) {
        EduEssay essay = this.getById(id);
        if (essay != null) {
            essay.setThumbUp(essay.getThumbUp() + 1); // 销量+1
            return this.updateById(essay); // 更新课程信息
        }
        return false;
    }

}
